#include <graphics.h>
#include <conio.h>
#include <math.h>
#define High 480
#define Width 640
#define pi 3.14159
int main()
{
	initgraph(Width, High);

	int center_x,center_y;//中心，秒针起始坐标
    center_x=Width/2;
	center_y=High/2;

	int secondlength;//秒针长度
    secondlength=Width/5;
	
	int minutelength;//分针长度
    minutelength=Width/8;
	
	int hourlength;//分针长度
    hourlength=Width/10;

	int second_end_x,second_end_y;//秒针终点
	float secondangle=0;//秒针转动角度

	int minute_end_x,minute_end_y;//分针终点
	float minuteangle=0;//分针转动角度

	int hour_end_x,hour_end_y;//时针终点
	float hourangle=0;//时针转动角度

    SYSTEMTIME ti;//定义变量存储时间

    BeginBatchDraw();

	circle(center_x,center_y,180);//表盘

	//数字,中点为160
    float angle=0;//角度
    int end_x,end_y;//终点
	
	for(angle=0;angle<=2*pi;angle=angle+pi/30.0)
	{
		end_x=center_x+160*sin(angle);
    	end_y=center_y-160*cos(angle);
		putpixel(end_x,end_y,WHITE);
	}
	setfillcolor(BLACK);
	for(angle=0;angle<=2*pi;angle=angle+pi/6.0)
	{
		end_x=center_x+160*sin(angle);
    	end_y=center_y-160*cos(angle);
		fillcircle(end_x,end_y,4);
	}
    setfillcolor(WHITE);
    for(angle=0;angle<=2*pi;angle=angle+pi/2.0)
	{  
		end_x=center_x+160*sin(angle);
    	end_y=center_y-160*cos(angle);
		bar(end_x-7,end_y-7,end_x+7,end_y+7);
	}

	outtextxy(295,350,"我的时钟");


	while(1)
	{
		GetLocalTime(&ti);
		//秒针
		secondangle=ti.wSecond*2*pi/60;
		
		second_end_x=center_x+secondlength*sin(secondangle);
    	second_end_y=center_y-secondlength*cos(secondangle);
	
    	//画秒针
    	setlinestyle(PS_SOLID,2);
    	setcolor(WHITE);
    	line(center_x,center_y,second_end_x,second_end_y);

        
        //分针
        minuteangle=ti.wMinute*2*pi/60;
		
		minute_end_x=center_x+minutelength*sin(minuteangle);
    	minute_end_y=center_y-minutelength*cos(minuteangle);
	
    	//画分针
    	setlinestyle(PS_SOLID,5);
    	setcolor(BLUE);
    	line(center_x,center_y,minute_end_x,minute_end_y);

		
		//时针
        hourangle=ti.wHour*2*pi/12;
		
		hour_end_x=center_x+hourlength*sin(hourangle);
    	hour_end_y=center_y-hourlength*cos(hourangle);
	
    	//画分针
    	setlinestyle(PS_SOLID,10);
    	setcolor(GREEN);
    	line(center_x,center_y,hour_end_x,hour_end_y);


        FlushBatchDraw();

		Sleep(50);

		//隐藏前一帧的秒针
		setcolor(BLACK);
		line(center_x,center_y,second_end_x,second_end_y);
		//隐藏前一帧的分针
        setcolor(BLACK);
		line(center_x,center_y,minute_end_x,minute_end_y);
		//隐藏前一帧的时针
		setcolor(BLACK);
		line(center_x,center_y,hour_end_x,hour_end_y);
	

	}

    EndBatchDraw();
	
	getch();
	closegraph();

	return 0;
}